/*
 * author      : 吴中勤 
 * date        : 2018/12/18
 * description : TODO
 */

package org.wzq.learn;

// stack OOM
/*
cd src
javac org/wzq/learn/JVMStackOOM.java
java -Xms20M -Xmx20M -Xmn10M -XX:+HeapDumpOnOutOfMemoryError -Xss160k org/wzq/learn/JVMStackOOM

java 1.8, 没有得到异常, 一致运行
*/
public class JVMStackOOM {
    private void dontStop() {
        while (true) {
        }
    }

    private void stackLeakByThread() {
        while (true) {
            Thread thread = new Thread(() -> dontStop());
            thread.start();
        }
    }

    public static void main(String[] args) {
        JVMStackOOM oom = new JVMStackOOM();
        oom.stackLeakByThread();
    }
}
